package leetcode_day._2021._202104._0110;

/**
 * @author yzh
 * @data 2021/4/1 22:49
 * 笨阶乘
 * 思路：
 *   四个数字一组
 *   当剩余数字 <= 3 时，返回具体的值
 */
public class _01_1006 {
    public static void main(String[] args) {
        System.out.println(new _01_1006().clumsy(4));
    }

    public int clumsy(int N) {
        int res = 0, flag = 1;
        while (true) {
            if (N <= 2) return res + flag * N;
            if (N == 3) return res + flag * 6;
            res += flag * N * (N - 1) / (N - 2) + (N - 3);
            flag = -1;
            N -= 4;
        }
    }
}
